import pygame
from pygame.sprite import Sprite

class Bullet(Sprite):
    """
    创建游戏子弹的类
    """
    def __init__ (self, alien_settings, screen, ship):
        # super(Bullet, self).__init__()
        super().__init__()

        self.screen = screen
        self.rect = pygame.Rect(0, 0, alien_settings.bullet_width, 
        alien_settings.bullet_height)

        self.rect.centerx = ship.image_rect.centerx
        self.rect.top = ship.image_rect.top
        self.y = float(self.rect.y)
        self.color = alien_settings.bullet_color
        self.speed_factor = alien_settings.bullet_speed_factor
        

    def update (self):
        """
        更新子弹的位置
        """
        self.y -= self.speed_factor

        self.rect.y = self.y

    
    def draw_bullet (self):
        """
        在屏幕上绘制子弹
        """

        pygame.draw.rect(self.screen, self.color, self.rect)